import 'package:flutter/material.dart';

import 'input_field.dart';

class AppSearchBar extends StatelessWidget {
  /// 是否点击触发重定位
  final Function? redirect;
  final bool searchIconVisible;
  final Widget? prefix;
  final String? hintText;
  final double? minHeight;

  const AppSearchBar(
      {super.key,
      this.redirect,
      this.searchIconVisible = true,
      this.prefix,
      this.hintText,
      this.minHeight});

  @override
  Widget build(BuildContext context) {
    /// when searchIconVisible is true, default icon
    Widget iconPrefix = prefix ??
        const Icon(
          Icons.search_rounded,
          size: 25,
          color: Color(0xffC8C6CD),
        );

    return Stack(
      children: [
        InputField(
          backgroundColor: const Color(0xffF5F6F8),
          borderRadius: 90,
          hintText: hintText ?? 'Search',
          minHeight: minHeight ?? 30,
          padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 5),
          prefix: searchIconVisible ? iconPrefix : null,
        ),
        redirect != null
            ? Positioned.fill(
                child: GestureDetector(
                  onTap: () {
                    redirect?.call();
                  },
                ),
              )
            : const SizedBox(),
      ],
    );
  }
}
